package com.example.threadmodel;

import com.example.threadmodel.utils.ActionUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;


/*
结论：可以拿到结果同步等待

消费者:
public class ArenaHandler{
    @OnProto(cmd=1)
    public void handleArenaInfo() {
        WorldService worldService = GameEngine.getInstance().getRemoteWorldService(1001);
        ArenaResponse response = worldService.multiArenaUpdateDefFormation(xx);
        ...
    }
}

服务提供者:
    @Override
    public ArenaResponse multiArenaUpdateDefFormation(ArenaRequest req) throws Exception {
        // 直接拿数据
        Action<MultiArenaRpcModel> action = ActionUtil.applyAction(req.getUid(), ActionName.MULTI_ARENA_UPDATE_DEF_FORMATION, () -> {
            return MultiArenaMasterService.getInstance().updateDefFightData(model);
        });
        return action.get();
    }
 */

@Slf4j
@SpringBootTest
public class Demo6_rpc_ActionCanSyncWait {
    @Test
    public void testRpc() {
        // 在rpc服务提供者执行
        int ret = ActionUtil.runWithReturn("1001", () -> {
            return 255;
        });

        log.info("ret={}", ret);
    }
}
